//
//  Y2DataStorage.m
//  Pods-Y2Common_Example
//
//  Created by Mac on 2021/5/31.
//

#import "Y2DataStorage.h"
#import "Y2StorageKeyChain.h"

@implementation Y2DataStorage

+(void) storageWithValue:(NSString *)obj key:(NSString *)key{
    NSUserDefaults *uds = [NSUserDefaults standardUserDefaults];
    [uds setValue:obj forKey:key];
    [uds synchronize];
}

+(NSString *) storageValueForKey:(NSString *)key{
    return [[NSUserDefaults standardUserDefaults] objectForKey:key];
}

+(BOOL) storageKeyChainWithValue:(id)obj{
    NSString * identifier = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"];
    NSError *error = nil;
    BOOL succcess= [Y2StorageKeyChain setPassword:obj
                                       forService:identifier
                                          account:[identifier stringByAppendingString:@".db"]
                                            error:&error];
    return succcess;
}

+(BOOL) storageKeyChainWithValue:(NSString *)obj
                             key:(NSString *)key
                    organization:(NSString *)organization{
    NSError *error = nil;
    BOOL succcess= [Y2StorageKeyChain setPassword:obj
                                       forService:organization
                                          account:key
                                            error:&error];
    return succcess;
}

+(NSString *) storageKeyChainForKey:(NSString *)key
                       organization:(NSString *)organization{
    return [Y2StorageKeyChain passwordForService:organization account:key];
}


@end
